/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Manish Mehta 
 												
Class							:				NotEnoughFoodBOFix
 
Function						: 				A class for holding a basic operator
												fix for situations when 
												not enough food is available
****************************************************************************/
package behavioradaptation.fixes;


import planninglanguage.plans.BuildBOPlan;
import planninglanguage.plans.MultiPlan;
import planninglanguage.plans.Plan;
import planninglanguage.plans.SequentialPlan;
import base.WargusGameState;
import base.WargusStateImporter;
import behavioradaptation.reasoner.GameStateHelpers;

public class NotEnoughFoodBOFix {
	public static Plan fix(Plan tobefixed,WargusGameState gameState)
	{
		int ID = -1;
		int i = 0;
		String []bldgs = {"town-hall","keep","castle","great-hall","stronghold","fortress"};
		
		for(i=0,ID=-1;i<6 && ID==-1;i++) {
			if(GameStateHelpers.GetUnitIDofType(gameState,0,bldgs[i]).size() != 0) {
				ID = GameStateHelpers.GetUnitIDofType(gameState,0,bldgs[i]).get(0);
			}
		}
		if (ID == -1) return null;
		// Find the closest match of x and y coordinates
		int x = 0, y = 0; 
		
		// The Fix is to build a farm to correct this situation 	
		MultiPlan fixedPlan = new SequentialPlan();
		fixedPlan.add( new BuildBOPlan(ID,x, y, WargusStateImporter.unitTypeToInteger("farm"),null,null,null) );
		fixedPlan.add((Plan) tobefixed.clone());
		
		return fixedPlan;
	}	
}
